package com.xywy.tangandroid.activity;

import java.util.List;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.xywy.tangandroid.R;
import com.xywy.tangandroid.bean.User;
import com.xywy.tangandroid.fragment.DoctorChurchFragement;
import com.xywy.tangandroid.fragment.ExperShareFragement;
/*
 * 名医堂
 */
public class DoctorChurchFrameAct extends FragmentActivity implements
		OnClickListener {

	private FragmentManager fm;

	// private RelativeLayout doctor_recomder;
	// private RelativeLayout expert_share;
	// private TextView doctor_recomder_text;
	// private TextView expert_share_text;
	private RelativeLayout left_img;

	private DoctorChurchFragement doctorFragement;
	private ExperShareFragement experShareFragement;

	private List<User> list;

	private TextView middle_title;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.act_doctor_phone);

		initview();
		fm = getSupportFragmentManager();
		initclickLister();
//		switchFragment(R.id.doctor_recomder);
		switchFragment(1);
	}

	private void initview() {
		left_img = (RelativeLayout) findViewById(R.id.left_img);
		middle_title = (TextView)findViewById(R.id.middle_title);
		middle_title.setText(getResources().getString(R.string.charch_doctor));
		
		// doctor_recomder_text = (TextView)
		// findViewById(R.id.doctor_recomder_text);
		// expert_share = (RelativeLayout) findViewById(R.id.expert_share);
		// expert_share_text = (TextView) findViewById(R.id.expert_share_text);
		// doctor_recomder=(RelativeLayout)findViewById(R.id.doctor_recomder);

	}

	private void initclickLister() {
		left_img.setOnClickListener(this);
		// doctor_recomder.setOnClickListener(this);
		// expert_share.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.left_img:
			finish();
			break;
		case R.id.doctor_recomder:
			switchFragment(R.id.doctor_recomder);
			break;
		case R.id.expert_share:
			switchFragment(R.id.expert_share);

			break;

		default:
			break;
		}
	}

	/**
	 * 
	 * @param id
	 */
	private void switchFragment(int id) {
		FragmentTransaction fragmentTransaction = fm.beginTransaction();
		hideFragments(fragmentTransaction);
		switch (id) {
		case R.id.doctor_recomder:

			// doctor_charch_rel.setVisibility(View.VISIBLE);
			// doctor_recomder.setBackgroundResource(R.color.text_color);
			// doctor_recomder_text.setTextColor(0xff333333);
			// expert_share.setBackgroundResource(R.color.tobar_background_color);
			// expert_share_text.setTextColor(0xffffffff);

			if (doctorFragement == null) {
				doctorFragement = new DoctorChurchFragement();
				fragmentTransaction.add(R.id.content_frame, doctorFragement);
			} else {
				fragmentTransaction.show(doctorFragement);
			}

			break;
		case R.id.expert_share:
			if (experShareFragement == null) {
				experShareFragement = new ExperShareFragement();
				fragmentTransaction
						.add(R.id.content_frame, experShareFragement);
			} else {
				fragmentTransaction.show(experShareFragement);
			}

			// doctor_charch_rel.setVisibility(View.GONE);
			// doctor_recomder
			// .setBackgroundResource(R.color.tobar_background_color);
			// doctor_recomder_text.setTextColor(0xffffffff);
			// expert_share.setBackgroundResource(R.color.text_color);
			// expert_share_text.setTextColor(0xff333333);
			break;
		   case 1:
			if (doctorFragement == null) {
				doctorFragement = new DoctorChurchFragement();
				fragmentTransaction.add(R.id.content_frame, doctorFragement);
			} else {
				fragmentTransaction.show(doctorFragement);
			}
			break;

		}
		fragmentTransaction.commit();
	}

	/**
	 * 
	 * @param transaction
	 */
	private void hideFragments(FragmentTransaction ft) {
		if (doctorFragement != null) {
			ft.hide(doctorFragement);
		}

		if (experShareFragement != null) {
			ft.hide(experShareFragement);
		}
	}

}